package com.buaa.xxx0321_1;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/3/25.
 */
public class SongAdapter extends BaseAdapter {

    private Context context;
    private List<Song> data;
    public SongAdapter(Context context, List<Song> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return data.get(position).getId();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        convertView = inflater.inflate(R.layout.song_layout,null);
        Song s = data.get(position);
        ImageView show = (ImageView)convertView.findViewById(R.id.show);
        show.setBackgroundResource(s.getShow());
        TextView title = (TextView)convertView.findViewById(R.id.title);
        title.setText(s.getTitle());
        TextView content = (TextView)convertView.findViewById(R.id.content);
        content.setText(s.getContent());
        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.i("xxx", data.get(position).getTitle());
            }
        });
        content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.i("xxx", data.get(position).getContent());
            }
        });

        return convertView;
    }
}
